<template>
    <div>
        <van-form>
            <div v-for='(i,index) in list'>
                <van-field v-for='j in i' :label='j.label' v-model='value[index+j.key]'/>
        </div>
            <van-button @click="add" color="linear-gradient(to right, #ff6034,#7232dd)">+</van-button><br><br>
            <van-button @click="save" color="linear-gradient(to left, #ff6034,#7232dd)">提交</van-button>
        </van-form>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                frorm:{},
                list:[[{'label':'名称','key':'name'},{'label':'类型','key':'type'},{'label':'字段名','key':'field'},{'label':'checkbox,radio,select值','key':'fvalue'}]],
                value:{},
                number:1,
                id:this.$route.query.id
            }
        },
        methods:{
            add(){
                this.number+=1
                this.list.push([{'label':'名称','key':'name'},{'label':'类型','key':'type'},{'label':'字段名','key':'field'},{'label':'checkbox,radio,select值','key':'fvalue'}])
                
            },
            save(){
                var list =[]
                for (var i=0;i<this.number;i++){
                    var name=i+'name'
                    var type=i+'type'
                    var field=i+'field'
                    var fvalue=i+'fvalue'
                    var dict={'name':this.value[name],'type':this.value[type],'field':this.value[field],'fvalue':this.value[fvalue]}
                    list.push(dict)
                }
                console.log(list)
                this.$axios.post('paramsM',{'id':this.id,'params':JSON.stringify(list)}).then(res=>{
                    alert('添加成功')
                })
            }
        }
    }
</script>

<style scoped>

</style>